import user.User;
import user.ProxyUser;
import user.factory.IUserFactory;
import user.factory.NormalUserFactory;
import user.factory.AdminUserFactory;
import java.util.Scanner;
public class LibrarySystem {
    public static void main(String[] args) {
        IUserFactory adminUserFactory = new AdminUserFactory();
        User admin = adminUserFactory.creatuser("小明", 1);

        IUserFactory normalUserFactory = new NormalUserFactory();
        User normal1 = normalUserFactory.creatuser("张三", 2);
        User normal2 = normalUserFactory.creatuser("李四", 3);

        ProxyUser proxyUserAdmin = new ProxyUser(admin);
        ProxyUser proxyUserNormal1 = new ProxyUser(normal1);
        ProxyUser proxyUserNormal2 = new ProxyUser(normal2);

        admin.display();
        LibrarySystem librarySystem = new LibrarySystem();
        ProxyUser currentUser = librarySystem.selectProxyRole(proxyUserAdmin, proxyUserNormal1, proxyUserNormal2);

        while (true) {
            int choice = currentUser.display();
            //如何实现 选择几（choice） 就执行 哪个用户（currentUser）的哪个操作？

            currentUser.handleOperation(choice);
        }
    }
    public  ProxyUser selectProxyRole(ProxyUser proxyUserAdmin,
    ProxyUser proxyUserNormal1,ProxyUser proxyUserNormal2) {

        System.out.println("选择角色进行登录：");
        System.out.println("1.管理员\n2.普通用户(张三)\n3.普通用户(李四)\n4.退出系统");
        ProxyUser currentUser = null;

        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();

        switch (choice) {
            case 1:
                currentUser = proxyUserAdmin;
                break;
            case 2:
                currentUser = proxyUserNormal1;
                break;
            case 3:
                currentUser = proxyUserNormal2;
                break;
            case 4:
                System.exit(0);
                System.out.println("退出系统了...");
                break;
            default:
                break;
        }
        return currentUser;
    }
}
